package JDBC;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class SQLupdate {
    public void funcName(int id, String newname, Connection connection) throws SQLException {
        String sql="update student set name = ? where id = ?";
        PreparedStatement statement=connection.prepareStatement(sql);
        statement.setString(1,newname);
        statement.setInt(2,id);
        int n=statement.executeUpdate();
        System.out.print("操作执行的行数为");
        System.out.println(n);
        statement.close();
    }

    public void funcId(int newid,String name,Connection connection)throws SQLException{
        String sql="update student set id = ? where name =?";
        PreparedStatement statement=connection.prepareStatement(sql);
        statement.setInt(1,newid);
        statement.setString(2,name);
        int n=statement.executeUpdate();
        System.out.print("操作执行的行数为");
        System.out.println(n);
        statement.close();
        connection.close();
    }
}
